import React from 'react';
import StateMixin from 'reflux-state-mixin';

import MenuAction from 'pages/framework/actions/menuAction'
import MenuStore from 'pages/framework/stores/menuStore'

export default React.createClass({
  mixins: [StateMixin.connect(MenuStore)],

  getDefaultProps() {
    return {
      configModules: [{
        "title": "服务项列表",
        "url": "serviceitems"
      },{
        "title": "服务目录",
        "url": "servicelist",
      },{
        "title": "服务标准",
        "url": "servicestandard"
      }],
      mapPathAndMenu: {
        "/service/serviceitems": 0,
        "/service/servicelist": 1,
        "/service/servicestandard": 2,
      }
    }
  },
  getCurrentByPath(pathname) {
    const index = this.props.mapPathAndMenu[pathname];
    let current = this.props.configModules[index];
    if (current) {
      return current;
    }
  },
  componentDidMount() {
    const path = this.props.location.pathname;
    const current = this.getCurrentByPath(path);
    if (current) {
      MenuAction.changeCurrent(current)
    }
  },
  componentDidUpdate(prevProps) {
    if (this.props.location.pathname !== prevProps.location.pathname) {
      const current = this.getCurrentByPath(this.props.location.pathname);
      if (current) {
        MenuAction.changeCurrent(current)
      }
    }
  },
  render() {
    return <div className="content-wrap"> { this.props.children } </div>
  }
})

